package com.fitns.user.controller.user;

import com.fitns.user.aop.annations.ZhhwAnnotation;
import com.fitns.user.conf.ZhhwResp;
import com.fitns.user.dto.user.LoginVO;
import com.fitns.user.dto.user.UserVO;
import com.fitns.user.service.user.LoginService;
import com.fitns.user.utils.ContextUtils;
import com.fitns.user.utils.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/login")
@RestController
@CrossOrigin
@Api(description = "登录")
public class LoginController {

    @Autowired
    private LoginService loginService;

    @ApiOperation("登录")
    @RequestMapping(method = RequestMethod.POST)
    @ZhhwAnnotation
    public  ResultData login(@RequestBody LoginVO loginVo) {
        UserVO userVo = loginService.login(loginVo);
        return new ResultData(200,"SUCESS",userVo,"");
    }

    @GetMapping("/token")
    @ApiOperation("获取token")
    public String getToken(){
        return ContextUtils.getToken();
    }


    @GetMapping("/sendValidateCode")
    @ApiOperation("获取验证码")
    public ResultData sendValidateCode(LoginVO loginVO){
        String validateCode= loginService.sendValidateCode(loginVO);
        return new ResultData(200,"SUCESS",validateCode,"");
    }

    @PostMapping("/forgetPassword")
    @ApiOperation("忘记密码")
    public ResultData forgetPassword(@RequestBody LoginVO loginVO){
        UserVO userVO= loginService.forgetPassword(loginVO);
        return new ResultData(200,"SUCESS",userVO,"");
    }

    @PostMapping("/loginOut")
    @ApiOperation("退出登录")
    public void loginOut(){
        loginService.loginOut();
    }

}
